from base.api import BaseApi
from account.controllers import setting as setting_ctl


class CreateSettingApi(BaseApi):

    need_params = {
        'name': ('名称', 'required str'),
        'path': ('路径', 'required str'),
    }
    def post(self, request, params):
        setting_ctl.create_setting(**params)


class UpdateSettingApi(BaseApi):

    need_params = {
        'obj_id': ('配置ID', 'required int'),
        'name': ('名称', 'required str'),
        'path': ('路径', 'required str'),
    }
    def post(self, request, params):
        setting_ctl.update_setting(**params)


class DeleteSettingApi(BaseApi):

    need_params = {
        'obj_id': ('配置ID', 'required int'),
    }
    def post(self, request, params):
        setting_ctl.delete_setting(**params)


class ListSettingApi(BaseApi):

    need_params = {
        'page_num': ('页码', 'optional int'),
        'page_size': ('页容量', 'optional int'),
    }
    def get(self, request, params):
        data = setting_ctl.get_settings(**params)
        return data


class SettingApi(BaseApi):

    need_params = {
        'obj_id': ('配置ID', 'required int'),
    }

    def get(self, request, params):
        data = setting_ctl.get_setting(**params)
        return data